///////////////////////////////////////////////////////////////////////////
//
// Spring Engine Source File.
// Copyright (C), Dengtao 2011-2021
// ----------------------------------------------------------------------
// File name:   SfGameObjectManager.h
// Version:     v1.0.0
// Created:     2013/06/16 11:06 by dengtao
// Compilers:   Visual Studio 2008
// Description: 
// ----------------------------------------------------------------------
// History:
//
///////////////////////////////////////////////////////////////////////////

#ifndef _SfGameObjectManager_H_
#define _SfGameObjectManager_H_

#include "SfGameObjectGUID.h"
#include "SfSharedSingleton.h"
#include <map>
#include <SfDelegate.h>

namespace Sunflower
{

class GameObject;

//////////////////////////////////////////////////////////////////////////
//Summary:
//	Game object mananger.
//////////////////////////////////////////////////////////////////////////
class GameObjectManager : public SharedSingleton<GameObjectManager>
{
public:
	//
	//Summary:
	//	constructor.
	GameObjectManager();

	//
	//Summary:
	//	destructor.
	virtual ~GameObjectManager();

	//
	//Summary:
	//	Register game object.
	void Register(GameObject* gameObject);

	//
	//Summary:
	//	Unregisgter game object.
	void Unregister(GameObject* gameObject);

	//
	//Summary:
	//	unregister all game objects.
	void UnregisterAll();

	//
	//Summary:
	//	find game object by goic.
	GameObject* GetGameObjectByGoid(const GameObjectGUID& goid);

	//
	//Summary:
	//	all game objects.
	virtual void IterateGameObjects(Delegate<void (GameObject*, void*)>& proc,
		void* args);

public:
	typedef std::map<GameObjectGUID, GameObject*> IDBasedGOMap;
	typedef IDBasedGOMap::iterator IDBasedGOMapIterator;
	typedef IDBasedGOMap::const_iterator IDBasedGOMapConstIterator;

	//
	//Summary:
	//	return IDBasedGOMap
	IDBasedGOMap& GetGoMap() { return m_GoidBasedDict; }
	const IDBasedGOMap& GetGoMap() const { return m_GoidBasedDict; }

private:
	// next valid id for generating Goid
	unsigned int m_NextValidID;

	// register map
	IDBasedGOMap m_GoidBasedDict;
};

}

#endif
